<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:margin-left="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="include :: header('员工基础信息列表')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="stfName"/>
                            </li>
                            <li>
                                <label>证件号：</label>
                                <input type="text" name="idCard"/>
                            </li>
                            <li>
                                <label>手机号码：</label>
                                <input type="text" name="phoneNumber"/>
                            </li>
                            <li>
                                <label>部门：</label>
                                <input type="text" name="stfDep"/>
                            </li>
                            <li>
                                <label>职位：</label>
                                <input type="text" name="stfPosition"/>
                            </li>
                            <li>
                                <label>学校：</label>
                                <input type="text" name="stfSchool"/>
                            </li>
                            <li>
                                <label>专业：</label>
                                <input type="text" name="stfMajor"/>
                            </li>
                            <li>
                                <label>毕业时间：</label>
                                <input type="text" class="time-input" placeholder="请选择毕业时间" name="stfEndDate"/>
                            </li>
                            <li>
                                <label>学历：</label>
                                <select name="stfDegree" class="form-control" type="text" th:with="type=${@dict.getType('staff_degree_type')}">
                                    <option value="">-----请选择-----</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
<!--                            <li>
                                <label>学位：</label>
                                <select name="stfDiploma" class="form-control" type="text" th:with="type=${@dict.getType('staff_diploma_type')}">
                                    <option value="">-&#45;&#45;&#45;&#45;请选择-&#45;&#45;&#45;&#45;</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>-->
                            <li>
                                <label>合同中止日期：</label>
                                <input type="text" class="time-input" placeholder="请选择合同中止日期" name="stfContractEndDate"/>
                            </li>
                            <li>
                                <label>社保卡卡号：</label>
                                <input type="text" name="socialSecurityId"/>
                            </li>
                            <li>
                                <label>公积金账号：</label>
                                <input type="text" name="accumulationFundId"/>
                            </li>
                            <li>
                                <label>婚姻状态：</label>
                                <select name="maritalStatus" class="form-control" type="text" th:with="type=${@dict.getType('marital_status')}">
                                    <option value="">-----请选择-----</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>入职时间：</label>
                                <input type="text" class="time-input" placeholder="请选择入职时间" name="stfHiredate"/>
                            </li>
                            <li>
                                <label>所属项目：</label>
                                <select id="projectId" name="projectId" class="form-control">
                                    <option value="">-----请选择-----</option>
                                    <option th:each="sysProject : ${sysProjectList}" th:text="${sysProject.projectName}" th:value="${sysProject.projectId}"></option>
                                </select>                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="staff:baseinfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="staff:baseinfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="staff:baseinfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-success" onclick="importExcel()" shiro:hasPermission="staff:baseinfo:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="staff:baseinfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info single disabled" onclick="importCertificate()" >
                    <i class="fa fa-upload"></i> 上传附件
                </a>
                <a class="btn btn-danger single disabled" onclick="exportCertificate()" >
                    <i class="fa fa-download"></i> 下载附件
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
     <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-fileinput-js" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('staff:baseinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('staff:baseinfo:remove')}]];
        var prefix = ctx + "staff/baseinfo";
        var degree_datas = [[${@dict.getType('staff_degree_type')}]];
        var diploma_datas = [[${@dict.getType('staff_diploma_type')}]];
        var marital_datas = [[${@dict.getType('marital_status')}]];
        var party_datas = [[${@dict.getType('staff_party_type')}]];


        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                uniqueId:"stfId",
                modalName: "员工基础信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'stfId',
                    title: '工号',
                    visible: false
                },
                {
                    field: 'stfName',
                    title: '姓名'
                },
                    {
                        field: 'idCard',
                        title: '证件号'
                    },
                {
                    field: 'phoneNumber',
                    title: '手机号码'
                },
                {
                    field: 'stfDep',
                    title: '部门'
                },
                {
                    field: 'stfPosition',
                    title: '职位'
                },
                {
                    field: 'stfSchool',
                    title: '学校'
                },
                {
                    field: 'stfMajor',
                    title: '专业'
                },
                {
                    field: 'stfEndDate',
                    title: '毕业时间'
                },
                {
                    field: 'stfDegree',
                    title: '学历',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(degree_datas, item.stfDegree);
                    }
                },
                {
                    field: 'stfDiploma',
                    title: '学位',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(diploma_datas, item.stfDiploma);
                    }
                },
                {
                    field: 'stfContractEndDate',
                    title: '合同中止日期'
                },
                {
                    field: 'socialSecurityId',
                    title: '社保卡卡号'
                },
                {
                    field: 'accumulationFundId',
                    title: '公积金账号'
                },
                {
                    field: 'emergencyContact',
                    title: '紧急联系人',
                    visible: false
                },
                {
                    field: 'maritalStatus',
                    title: '婚姻状态',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(marital_datas, item.maritalStatus);
                    }
                },
                {
                    field: 'stfHiredate',
                    title: '入职时间'
                },
                {
                    field: 'isParty',
                    title: '是否入党',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(party_datas, item.isParty);
                    }
                },
                {
                    field: 'partyTime',
                    title: '入党时间'
                },
                {
                    field: 'projectName',
                    title: '所属项目'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.stfId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.stfId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 保存家庭成员
         **/


        /**
         * 导入
         * */
        function importExcel(formId, width, height) {
            table.set();
            var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
            var _width = $.common.isEmpty(width) ? "400" : width;
            var _height = $.common.isEmpty(height) ? "230" : height;
            layer.open({
                type: 1,
                area: [_width + 'px', _height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '导入' + table.options.modalName + '数据',
                content: $('#' + currentId).html(),
                btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
                // 弹层外区域关闭
                shadeClose: true,
                btn1: function(index, layero){
                    var file = layero.find('#drfile').val();
                    if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
                        $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                        return false;
                    }
                    var index = layer.load(2, {shade: false});
                    $.modal.disable();
                    var formData = new FormData(layero.find('form')[0]);
                    $.ajax({
                        url:prefix + "/importExcel",
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'POST',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $.modal.closeAll();
                                $.modal.alertSuccess(result.msg);
                                $.table.refresh();
                            } else if (result.code == web_status.WARNING) {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertWarning(result.msg)
                            } else {
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertError(result.msg);
                            }
                        }
                    });
                }
            });
        }


        /**
         * 上传资质证书
         * */
        function importCertificate() {
            var stfIds = $.table.selectColumns("stfId");
            layer.open({
                type: 1,
                area: ['600px','400px'],
                fix:false,
                maxmin:true,
                shade:0.3,
                title:'上传附件',
                content:$('#importAddTpl').html(),
                btn:['<i class="fa fa-check"></i>导入','<i class="fa fa-remove"></i>取消'],
                //弹层外区域关闭
                shadeClose:true,
                btn1:function (index,layero) {
                    var filename = layero.find('#file').val();
                    if(filename == ''){
                        $.modal.msgWarning("请选择需要上传的文件！");
                        return false;
                    }
                    var index = layer.load(2,{shade:false});
                    $.modal.disable();
                    var formData = new FormData(layero.find('form')[0]);
                    formData.append("stfIds", stfIds);
                    $.ajax({
                        url:prefix + "/importCertificate",
                        data:formData,
                        cache:false,
                        contentType:false,
                        processData:false,
                        type:'POST',
                        success:function( result){
                            if(result.code == web_status.SUCCESS){
                                $.modal.closeAll();
                                $.modal.alertSuccess(result.msg);
                                $.table.refresh();
                            }else if (result.code == web_status.WARNING){
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertWarning(result.msg);
                            }else{
                                layer.close(index);
                                $.modal.enable();
                                $.modal.alertError(result.msg);
                            }
                        }
                    })
                }
            })

        }
        //导出员工基础信息
        function exportExcel(){
            var rows=$.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            };
            $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function() {
                var url = table.options.exportUrl;
                var data = { "ids": rows.join() };
                $.modal.loading("正在导出数据，请稍后...");
                $.post(url,data,function (res) {
                    if (res.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                    } else if (res.code == web_status.WARNING) {
                        $.modal.alertWarning(res.msg)
                    } else {
                        $.modal.alertError(res.msg);
                    }
                    $.modal.closeLoading();
                })
            });
        }

        function getProjectName(value){
            var datas =[[${sysProjectList}]];

            if ($.common.isEmpty(datas) || $.common.isEmpty(value)) {
                    return '';
                }
                var actions = [];
                $.each(datas, function(index, dict) {
                    if (dict.dictValue == ('' + value)) {
                        var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
                        actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
                        return false;
                    }
                });
                return actions.join('');
        }
    </script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="drfile" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的员工基础信息数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<script id="importAddTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <span class="btn btn-white btn-file">
            <span class="fileinput-new">仅支持上传文件格式：BMP, GIF,JPG,JPEG,PNG!</span>
        </span>
        <div class="col-xs-offset-l">
            <input style="margin-left: 20px" type="file" id="file" name="file"/>
        </div>
    </form>
</script>
</html>